home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / Hydra11s.lha / HBBS / Source / Utils / UserViewer / Main.C < prev    next >
C/C++ Source or Header  |  1996-06-25  |  6KB  |  280 lines

  1.  
  2. #include <exec/types.h>
  3. #include <exec/memory.h>
  4. #include <dos/dos.h>
  5. #include <clib/exec_protos.h>
  6. #include <clib/dos_protos.h>
  7. #include <clib/alib_protos.h>
  8.  
  9. #include <dos/dosextens.h>
  10. #include <intuition/screens.h>
  11. #include <intuition/intuition.h>
  12. #include <intuition/gadgetclass.h>
  13. #include <libraries/gadtools.h>
  14. #include <diskfont/diskfont.h>
  15. #include <utility/utility.h>
  16. #include <graphics/gfxbase.h>
  17. #include <workbench/workbench.h>
  18. #include <graphics/scale.h>
  19. #include <clib/wb_protos.h>
  20. #include <clib/intuition_protos.h>
  21. #include <clib/gadtools_protos.h>
  22. #include <clib/graphics_protos.h>
  23. #include <clib/utility_protos.h>
  24. #include <string.h>
  25. #include <clib/diskfont_protos.h>
  26.  
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include <stdio.h>
  30. #include <ctype.h>
  31. #include <time.h>
  32.  
  33. #include <libraries/reqtools.h>
  34. #include <clib/reqtools_protos.h>
  35.  
  36. #include "UserViewer.h"
  37.  
  38. #ifdef __SASC
  39. int CXBRK(void) { return(0); }
  40. int _CXBRK(void) { return(0); }
  41. void chkabort(void) {}
  42. #endif
  43.  
  44. #include <HBBS/ANSI_Codes.h>
  45. #include <HBBS/Defines.h>
  46. #include <HBBS/types.h>
  47. #include <HBBS/structures.h>
  48. #include <HBBS/hbbscommon_protos.h>
  49. #include <HBBS/hbbscommon_pragmas.h>
  50. #include <HBBS/Hbbsnode_protos.h>
  51. #include <HBBS/Hbbsnode_pragmas.h>
  52.  
  53. struct ReqToolsBase *ReqToolsBase;
  54. struct Library *HBBSCommonBase=NULL;
  55. struct Library *HBBSNodeBase=NULL;
  56. struct List *UserList;
  57. struct NodeData *NodePtr;
  58.  
  59. struct BBSGlobalData *BBSGlobal=NULL;
  60.  
  61. ULONG rttags[] =
  62. {
  63.   RTGS_Flags, GSREQF_CENTERTEXT,
  64.   RT_Underscore, '_',
  65.   RTEZ_ReqTitle, (ULONG)"About User Viewer",
  66.   RT_PubScrName, (ULONG)"CtrlScrn",
  67.   TAG_END
  68. };
  69.  
  70. char tmpstr[1024];
  71. static VOID cleanup(ULONG num)
  72. {
  73.   if (HBBSCommonBase)
  74.   {
  75.     HBBS_CleanUpCommon();
  76.     CloseLibrary (HBBSCommonBase);
  77.   }
  78.  
  79.   if (ReqToolsBase)
  80.     CloseLibrary ((struct Library *)ReqToolsBase);
  81.  
  82.   if (num) printf("Door Error = %d\n",num);
  83.  
  84.   exit(0);
  85. }
  86.  
  87. static VOID init(char *name)
  88. {
  89.   if (!(ReqToolsBase = (struct ReqToolsBase *) OpenLibrary (REQTOOLSNAME, REQTOOLSVERSION)))
  90.   {
  91.     cleanup(0);
  92.   }
  93.  
  94.   if(!(HBBSCommonBase = OpenLibrary("HBBSCommon.library",0)))
  95.   {
  96.     cleanup(1);
  97.   }
  98.  
  99.   if (!(HBBS_InitCommon()))
  100.   {
  101.     cleanup(2);
  102.   }
  103.  
  104.   SetProgramName(name);
  105. }
  106.  
  107. void UpdateWindow ( void )
  108. {
  109.   int loop;
  110.   struct Node *usernode;
  111.  
  112.   // turn of list before we modify it..
  113.   GT_SetGadgetAttrs(UVGadgets[LV1],UV,NULL,GTLV_Labels,NULL,GTLV_Top,0,TAG_DONE);
  114.  
  115.   for (loop=0;loop<BBSGlobal->BBSNodes;loop++)
  116.   {
  117.     usernode=GetNode(UserList,loop);
  118.  
  119.     FreeStr(usernode->ln_Name);
  120.  
  121.     NodePtr=HBBS_NodeDataPtr(loop);
  122.     switch (NodePtr->Status)
  123.     {
  124.       case STAT_READY:
  125.         sprintf(tmpstr,"Node %d Is Awaiting Connect!",loop);
  126.         break;
  127.       case STAT_ONLINE:
  128.         if (NodePtr->User.Valid)
  129.         {
  130.           sprintf(tmpstr,"Node %d, User: %s, Group: %s, Baud/CPS: %s",loop,NodePtr->User.CallData.Handle,NodePtr->User.CallData.Group,NodePtr->ConnectBaud);
  131.         }
  132.         else
  133.         {
  134.           sprintf(tmpstr,"Node %d, User has not logged in yet!",loop);
  135.         }
  136.         break;
  137.       case STAT_CLOSED:
  138.         sprintf(tmpstr,"Node %d is closed.",loop);
  139.         break;
  140.       default:
  141.         sprintf(tmpstr,"Node %d is processing.",loop);
  142.         break;
  143.     }
  144.     usernode->ln_Name=DupStr(tmpstr);
  145.   }
  146.  
  147.   GT_SetGadgetAttrs(UVGadgets[LV1],UV,NULL,GTLV_Labels,UserList,GTLV_Top,0,TAG_DONE);
  148. }
  149.  
  150. int ProcessWindowUV( LONG Class, UWORD Code, APTR IAddress )
  151. {
  152. struct Gadget *gad;
  153. switch ( Class )
  154.   {
  155.   case IDCMP_GADGETUP :
  156.     /* Gadget message, gadget = gad. */
  157.     gad = (struct Gadget *)IAddress;
  158.     switch ( gad->GadgetID )
  159.       {
  160.       case LV1 :
  161.       case UV_UPDATE :
  162.         /* ListView pressed, Text of gadget :  */
  163.         UpdateWindow();
  164.         break;
  165.       case UV_ABOUT :
  166.         sprintf(tmpstr,"UserViewer\n"
  167.                        "==========\n"
  168.                        "(C) 1995 Dominic Clifton\n"
  169.                        "Deluxe Software Limited!\n");
  170.         rtEZRequest(tmpstr,"Ok!",NULL,(struct TagItem *)&rttags,NULL);
  171.       }
  172.     break;
  173.   case IDCMP_CLOSEWINDOW :
  174.     /* CloseWindow Now */
  175.     return(1);
  176.     break;
  177.   case IDCMP_REFRESHWINDOW :
  178.     GT_BeginRefresh( UV);
  179.     /* Refresh window. */
  180.   RendWindowUV( UV, UVVisualInfo );
  181.     GT_EndRefresh( UV, TRUE);
  182.   GT_RefreshWindow( UV, NULL);
  183.   RefreshGList( UVGList, UV, NULL, ~0);
  184.     break;
  185.   }
  186.   return(0);
  187. }
  188.  
  189. #define WAIT_TIME 30
  190.  
  191. void DoorMain(int argc,char *argv[])
  192. {
  193.   int done=0;
  194.   ULONG class;
  195.   UWORD code;
  196.   struct Gadget *pgsel;
  197.   struct IntuiMessage *imsg;
  198.   ULONG ReturnedSig;
  199.   struct Screen *CtrlScr;
  200.  
  201.   int loop;
  202.   struct TimerSetupData *TSD;
  203.   struct TimerData *TD;
  204.  
  205.   if (TSD=InitTimer())
  206.   {
  207.  
  208.  
  209.     if (UserList=AllocVec(sizeof(struct List),MEMF_PUBLIC))
  210.     {
  211.       NewList(UserList);
  212.  
  213.  
  214.       for (loop=0;loop<BBSGlobal->BBSNodes;loop++)
  215.       {
  216.         if (NodePtr=HBBS_NodeDataPtr(loop))
  217.         {
  218.           NewStrNode("Initialising..",UserList);
  219.         }
  220.       }
  221.  
  222.       if (CtrlScr=LockPubScreen(BBSGlobal->ScreenInfo.PubScreenName))
  223.       {
  224.         ScreenToFront(CtrlScr);
  225.         if (OpenWindowUV(CtrlScr)==0)
  226.         {
  227.           UnlockPubScreen(NULL,CtrlScr);
  228.           UpdateWindow();
  229.           if (TD=SubmitTimer(TSD,WAIT_TIME,0))
  230.           {
  231.             while(done==0)
  232.             {
  233.               ReturnedSig=Wait(1L << UV->UserPort->mp_SigBit | 1 << TSD->TimerPort->mp_SigBit);
  234.  
  235.               if ((CheckTimer(TSD,TD)) || (ReturnedSig & 1L << TSD->TimerPort->mp_SigBit))
  236.               {
  237.                 AbortTimer(TSD,TD); // clean it up..
  238.  
  239.                 UpdateWindow();
  240.  
  241.                 TD=SubmitTimer(TSD,WAIT_TIME,0);
  242.               }
  243.  
  244.               if (ReturnedSig & 1L << UV->UserPort->mp_SigBit)
  245.               {
  246.                 while (imsg=GT_GetIMsg(UV->UserPort))
  247.                 {
  248.                   class=imsg->Class;
  249.                   code=imsg->Code;
  250.                   pgsel=(struct Gadget *)imsg->IAddress;
  251.  
  252.                   GT_ReplyIMsg(imsg);
  253.  
  254.                   done=ProcessWindowUV(class, code, pgsel);
  255.                 }
  256.               }
  257.             }
  258.             AbortTimer(TSD,TD);
  259.           }
  260.           CloseWindowUV();
  261.         } else UnlockPubScreen(NULL,CtrlScr);
  262.       }
  263.       else puts("Error Opening Window!");
  264.       FreeStrList(UserList);
  265.     }
  266.     CleanupTimer(TSD);
  267.   }
  268. }
  269.  
  270. int main(int argc,char *argv[])
  271. {
  272.   init("UserViewer");
  273.  
  274.   if (BBSGlobal=HBBS_GimmeBBS())
  275.   {
  276.       DoorMain(argc,argv);
  277.   }
  278.   cleanup(0);
  279. }
  280.